/*
 *  WellTemperamentTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 11/06/13.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#include "WellTemperamentTester.h"

#include "../Common/WellTemperament.h"
#include "CustomAssert.h"

namespace sc
{
	void WellTemperamentTester::TestAll()
	{
		std::cout << "WellTemperamentTester start" << std::endl;

		Test_GetFrequency();

		Test_GetMidiNoteNumber();

		std::cout << "WellTemperamentTester end" << std::endl;
	}

	void WellTemperamentTester::Test_GetFrequency()
	{
		AssertEqual( WellTemperament::GetFrequency( Note::C2 ), ( 1.0 / 8.0 ) * pow( 2.0 , 3.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::DFlat2 ), ( 1.0 / 8.0 ) * pow( 2.0 , 4.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::D2 ), pow( 2.0 , ( 5.0 - 36.0 ) / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::EFlat2 ), ( 1.0 / 8.0 ) * pow( 2.0 , 6.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::E2 ), pow( 2.0 , ( 7.0 - 36.0 ) / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::F2 ), ( 1.0 / 8.0 ) * pow( 2.0 , 8.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::GFlat2 ), ( 1.0 / 8.0 ) * pow( 2.0 , 9.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::G2 ), pow( 2.0 , ( 10.0 - 36.0 ) / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::AFlat2 ), ( 1.0 / 8.0 ) * pow( 2.0 , 11.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::A2 ), ( 1.0 / 4.0 ) * pow( 2.0 , 0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::BFlat2 ), ( 1.0 / 4.0 ) * pow( 2.0 , 1.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::B2 ), ( 1.0 / 4.0 ) * pow( 2.0 , 2.0 / 12.0 ) * WellTemperament::baseFrequency );


		AssertEqual( WellTemperament::GetFrequency( Note::C3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 3.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::DFlat3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 4.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::D3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 5.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::EFlat3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 6.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::E3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 7.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::F3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 8.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::GFlat3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 9.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::G3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 10.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::AFlat3 ), ( 1.0 / 4.0 ) * pow( 2.0 , 11.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::A3 ), ( 1.0 / 2.0 ) * pow( 2.0 , 0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::BFlat3 ), ( 1.0 / 2.0 ) * pow( 2.0 , 1.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::B3 ), ( 1.0 / 2.0 ) * pow( 2.0 , 2.0 / 12.0 ) * WellTemperament::baseFrequency );

		AssertEqual( WellTemperament::GetFrequency( Note::C4 ), ( 1.0 / 2.0 ) * pow( 2.0 , 3.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::DFlat4 ), ( 1.0 / 2.0 ) * pow( 2.0 , 4.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::D4 ), ( 1.0 / 2.0 ) * pow( 2.0 , 5.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::EFlat4 ), pow( 2.0 , -6.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::E4 ), ( 1.0 / 2.0 ) * pow( 2.0 , 7.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::F4 ), ( 1.0 / 2.0 ) * pow( 2.0 , 8.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::GFlat4 ), ( 1.0 / 2.0 ) * pow( 2.0 , 9.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::G4 ), ( 1.0 / 2.0 ) * pow( 2.0 , 10.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::AFlat4 ), ( 1.0 / 2.0 ) * pow( 2.0 , 11.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::A4 ), pow( 2.0 , 0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::BFlat4 ), pow( 2.0 , 1.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::B4 ), pow( 2.0 , 2.0 / 12.0 ) * WellTemperament::baseFrequency );

		AssertEqual( WellTemperament::GetFrequency( Note::C5 ), pow( 2.0 , 3.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::DFlat5 ), pow( 2.0 , 4.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::D5 ), pow( 2.0 , 5.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::EFlat5 ), pow( 2.0 , 6.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::E5 ), pow( 2.0 , 7.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::F5 ), pow( 2.0 , 8.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::GFlat5 ), pow( 2.0 , 9.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::G5 ), pow( 2.0 , 10.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::AFlat5 ), pow( 2.0 , 11.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::A5 ), 2 * pow( 2.0 , 0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::BFlat5 ), 2 * pow( 2.0 , 1.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::B5 ), 2 * pow( 2.0 , 2.0 / 12.0 ) * WellTemperament::baseFrequency );

		AssertEqual( WellTemperament::GetFrequency( Note::C6 ), 2 * pow( 2.0 , 3.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::DFlat6 ), 2 * pow( 2.0 , 4.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::D6 ), 2 * pow( 2.0 , 5.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::EFlat6 ), 2 * pow( 2.0 , 6.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::E6 ), 2 * pow( 2.0 , 7.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::F6 ), 2 * pow( 2.0 , 8.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::GFlat6 ), 2 * pow( 2.0 , 9.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::G6 ), 2 * pow( 2.0 , 10.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::AFlat6 ), 2 * pow( 2.0 , 11.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::A6 ), 4 * pow( 2.0 , 0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::BFlat6 ), 4 * pow( 2.0 , 1.0 / 12.0 ) * WellTemperament::baseFrequency );
		AssertEqual( WellTemperament::GetFrequency( Note::B6 ), pow( 2.0 , ( 24.0 + 2.0 ) / 12.0 ) * WellTemperament::baseFrequency );

	}

	void WellTemperamentTester::Test_GetMidiNoteNumber()
	{
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::C2 ) ), Note::C2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::DFlat2 ) ), Note::DFlat2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::D2 ) ), Note::D2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::EFlat2 ) ), Note::EFlat2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::E2 ) ), Note::E2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::F2 ) ), Note::F2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::GFlat2 ) ), Note::GFlat2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::G2 ) ), Note::G2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::AFlat2 ) ), Note::AFlat2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::A2 ) ), Note::A2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::BFlat2 ) ), Note::BFlat2 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::B2 ) ), Note::B2 );


		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::C3 ) ), Note::C3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::DFlat3 ) ), Note::DFlat3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::D3 ) ), Note::D3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::EFlat3 ) ), Note::EFlat3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::E3 ) ), Note::E3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::F3 ) ), Note::F3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::GFlat3 ) ), Note::GFlat3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::G3 ) ), Note::G3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::AFlat3 ) ), Note::AFlat3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::A3 ) ), Note::A3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::BFlat3 ) ), Note::BFlat3 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::B3 ) ), Note::B3 );

		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::C4 ) ), Note::C4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::DFlat4 ) ), Note::DFlat4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::D4 ) ), Note::D4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::EFlat4 ) ), Note::EFlat4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::E4 ) ), Note::E4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::F4 ) ), Note::F4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::GFlat4 ) ), Note::GFlat4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::G4 ) ), Note::G4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::AFlat4 ) ), Note::AFlat4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::A4 ) ), Note::A4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::BFlat4 ) ), Note::BFlat4 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::B4 ) ), Note::B4 );

		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::C5 ) ), Note::C5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::DFlat5 ) ), Note::DFlat5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::D5 ) ), Note::D5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::EFlat5 ) ), Note::EFlat5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::E5 ) ), Note::E5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::F5 ) ), Note::F5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::GFlat5 ) ), Note::GFlat5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::G5 ) ), Note::G5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::AFlat5 ) ), Note::AFlat5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::A5 ) ), Note::A5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::BFlat5 ) ), Note::BFlat5 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::B5 ) ), Note::B5 );

		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::C6 ) ), Note::C6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::DFlat6 ) ), Note::DFlat6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::D6 ) ), Note::D6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::EFlat6 ) ), Note::EFlat6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::E6 ) ), Note::E6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::F6 ) ), Note::F6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::GFlat6 ) ), Note::GFlat6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::G6 ) ), Note::G6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::AFlat6 ) ), Note::AFlat6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::A6 ) ), Note::A6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::BFlat6 ) ), Note::BFlat6 );
		AssertEqual( WellTemperament::GetMidiNoteNumber( WellTemperament::GetFrequency( Note::B6 ) ), Note::B6 );

	}

}
